# -*- coding: utf-8 -*-
# @Time    : 2021/11/27 14:43
# @Author  : zhangyi
# @FileName: pre_word2def.py
# @Software: vscode

'''
从def2word 生成 word2def
'''

import re
import pickle
if __name__=='__main__':        
    def2word,word2def=dict(),dict()
    words=[]
    with open(r'Def2word.txt','r',encoding='utf-8') as ref:
        content=ref.readlines()
        print(len(content))
        for i in range(len(content)):
            ret=re.search('^\#(.+)',content[i].strip())
            if ret:
                key=ret.group(1).split('|')[1]
            else:
                def2word.setdefault(key,[]).append(content[i].strip().split()[0])
                word2def.setdefault(content[i].strip().split()[0],[]).append(key)
    with open("word2def.pkl",'wb') as out_file:
        pickle.dump(word2def,out_file)   
    with open("word2def.pkl",'rb') as file:
        dada=pickle.load(file)
    print(dada['稀'])

